/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxline.atlasmobile.manager;

import br.com.foxline.atlasmobile.enums.TipoDocumento;
import br.com.foxline.model.Endereco;
import br.com.foxline.model.Imovel;
import br.com.foxline.model.Proprietario;
import br.com.foxline.service.ImovelService;
import br.com.foxline.util.Caracter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import javax.servlet.ServletContext;

/**
 *
 * @author ely
 */
@ViewScoped
@ManagedBean
public class ManagerMemorialDescritivo {

    @EJB
    ImovelService imovelDao;
    private Proprietario proprietario;
    private Endereco endereco;
    private List<Imovel> imoveis;
    private Imovel imovel;

    @PostConstruct
    public void init() {
        imoveis = new ArrayList<Imovel>();
        proprietario = new Proprietario();
        endereco = new Endereco();
        imovel = new Imovel();

        proprietario.setTipoDocumento(TipoDocumento.CPF);
    }

    public void searchImovel() {
        proprietario.setCpf(Caracter.removecaracter(proprietario.getCpf()));
        proprietario.setCnpj(Caracter.removecaracter(proprietario.getCnpj()));
        endereco.setCep(Caracter.removecaracter(endereco.getCep()));
        imoveis = imovelDao.findImoveis(imovel, proprietario, endereco);
    }

    public void reportMemorial(Imovel imovel) {
        HashMap parametros = new HashMap();
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext();
        parametros.put("img", servletContext.getRealPath("/media/images/brasao.jpg"));

        imovelDao.reportMemorial(parametros, imovel);
 
    }

    public void reportMemorialDescritivo() {
        HashMap parametros = new HashMap();
        proprietario.setCpf(Caracter.removecaracter(proprietario.getCpf()));
        proprietario.setCnpj(Caracter.removecaracter(proprietario.getCnpj()));
        endereco.setCep(Caracter.removecaracter(endereco.getCep()));

        FacesContext facesContext = FacesContext.getCurrentInstance();
        ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext();


        parametros.put("img", servletContext.getRealPath("/media/images/brasao.jpg"));
        imovelDao.reportsMemorialDescritivo(parametros, imovel, proprietario, endereco);
    }

    public List<SelectItem> tipoDocumento() {
        List<SelectItem> items = new ArrayList<SelectItem>();
        for (TipoDocumento tipo : TipoDocumento.values()) {
            items.add(new SelectItem(tipo.getTipo(), tipo.getNome()));
        }
        return items;
    }

    public Proprietario getProprietario() {
        return proprietario;
    }

    public void setProprietario(Proprietario proprietario) {
        this.proprietario = proprietario;
    }

    public Endereco getEndereco() {
        return endereco;
    }

    public void setEndereco(Endereco endereco) {
        this.endereco = endereco;
    }

    public List<Imovel> getImoveis() {
        return imoveis;
    }

    public void setImoveis(List<Imovel> imoveis) {
        this.imoveis = imoveis;
    }

    public Imovel getImovel() {
        return imovel;
    }

    public void setImovel(Imovel imovel) {
        this.imovel = imovel;
    }
}
